package com.cqie.rbac.controller;


import com.cqie.rbac.bo.PageRoleBo;
import com.cqie.rbac.bo.RoleStatusBo;
import com.cqie.rbac.bo.RoleUpOrAddBo;
import com.cqie.rbac.service.ISysRoleService;
import com.cqie.rbac.util.Result;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色实体 前端控制器
 * </p>
 *
 * @author 夏兵
 * @since 2021-09-02
 */
@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Autowired
    private ISysRoleService iSysRoleService;

    @GetMapping("/getRole")
    @RequiresPermissions(value = {"all_user", "add_user", "modify_user"}, logical = Logical.OR)
    public Result getRole() {
        return iSysRoleService.getRole();
    }

    @PostMapping("/pageOfRole")
    @RequiresPermissions(value = {"all_role", "add_role", "modify_role", "lock_role"}, logical = Logical.OR)
    public Result pageOfRole(@RequestBody PageRoleBo pageRoleBo, Integer current, Integer size) {
        return iSysRoleService.pageOfRole(pageRoleBo, current, size);
    }

    @PostMapping("/changeRoleStatus")
    @RequiresPermissions(value = {"all_role", "lock_role"}, logical = Logical.OR)
    public Result changeRoleStatus(@RequestBody RoleStatusBo roleStatusBo) {
        return iSysRoleService.changeRoleStatus(roleStatusBo);
    }

    @PostMapping("/multiChangeRoleStatus")
    @RequiresPermissions(value = {"all_role", "lock_role"}, logical = Logical.OR)
    public Result multiChangeRoleStatus(@RequestBody List<RoleStatusBo> roleStatusBos) {
        return iSysRoleService.multiChangeRoleStatus(roleStatusBos);
    }

    @PostMapping("/multiDelRole")
    @RequiresPermissions(value = {"all_role", "del_role"}, logical = Logical.OR)
    public Result multiDelRole(@RequestBody Long[] idArray) {
        return iSysRoleService.multiDelRole(idArray);
    }

    @PostMapping("/roleUpOrAdd")
    @RequiresPermissions(value = {"all_role", "add_role", "modify_role"}, logical = Logical.OR)
    public Result roleUpOrAdd(@RequestBody RoleUpOrAddBo roleUpOrAddBo) {
        return iSysRoleService.roleUpOrAdd(roleUpOrAddBo);
    }
}
